package com.mystudy;

/**
 * 将本地test4.txt文件上传至HDFS的/17124080120/下
 */
import java.net.URI;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
/**
 * HDFS Upload
 */
public class UploadHDFSFile {
    public static void main(String[] args) throws Exception{
        Configuration conf = new Configuration();
        //配置NameNode地址
        URI uri = new URI("hdfs://192.168.30.130:8020");
        //指定用户名，获取FileSystem地址
        FileSystem fs = FileSystem.get(uri,conf,"hadoop");
        //Local file
        Path src = new Path("e:\\test4.txt");
        //HDFS file
        Path dst = new Path("/17124080120/test4.txt");
        fs.copyFromLocalFile(src,dst);
        //不需要再操作FileSystem了，关闭
        fs.close();
        System.out.println("Upload Successfully!");
    }
}
